using FluffyUnderware.DevTools.Extensions;
using System.Reflection;
using UnityEngine;

namespace FluffyUnderware.DevTools
{
	public class ActionAttribute : DTAttribute
	{
		public enum ActionEnum
		{
			Show,
			Hide,
			Enable,
			Disable,
			ShowInfo,
			ShowWarning,
			ShowError,
			Callback
		}

		public enum ActionPositionEnum
		{
			Above,
			Below
		}

		public ActionEnum Action = ActionEnum.Callback;

		public ActionPositionEnum Position = ActionPositionEnum.Below;

		public object ActionData;

		private MethodInfo mCallback;

		protected ActionAttribute(string actionData, ActionEnum action = ActionEnum.Callback)
			: base(50)
		{
			ActionData = actionData;
			Action = action;
		}

		public void Callback(object classInstance)
		{
			string text = ActionData as string;
			if (!string.IsNullOrEmpty(text))
			{
				if (mCallback == null)
				{
					mCallback = classInstance.GetType().MethodByName(text, includeInherited: true, includePrivate: true);
				}
				if (mCallback != null)
				{
					mCallback.Invoke(classInstance, null);
				}
				else
				{
					UnityEngine.Debug.LogWarningFormat("[DevTools] Unable to find method '{0}' at class '{1}' !", text, classInstance.GetType().Name);
				}
			}
		}
	}
}
